function fn(time) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve({
        value: time,
        done: false
      })
    }, time)
  })
}
const arr = [fn(1000), fn(2000), fn(3000)]
arr[Symbol.asyncIterator] = function () {
  let nextIndex = 0
  return {
    next() {
      return nextIndex < arr.length ? arr[nextIndex++] : Promise.resolve({ value: undefined, done: true })
    }
  }
}
//  ! 将整个异步函数转换为一个函数表达式
!(async function test() {
  // for await 遍历过程中依次执行每一个异步函数，而不是瞬间全部执行
  for await (let item of arr) {
    console.log(item) // 依此输出 1000 2000 3000
  }
})()
